package homework.api01.apitest01;

public class StringBuilderDemo {
    public static void main(String[] args) {
        //append添加
        String str = "好好学习Java";
        StringBuilder builder = new StringBuilder(str);
        builder.append(",为了找个好工作");
        System.out.println(builder);//好好学习Java,为了找个好工作

        //replace替换---含头不含尾
        builder.replace(9,16,"为了拯救世界");
        System.out.println(builder);//好好学习Java,为了拯救世界

        //delete删除
        builder.delete(0,8);
        System.out.println(builder);//,为了拯救世界

        //insert插入
        builder.insert(0,"活着");
        System.out.println(builder);//活着,为了拯救世界

        //reverse反转----倒序输出
        builder.reverse();
        System.out.println(builder);//界世救拯了为,着活

        String str1 = "abc";
        StringBuilder builder1 = new StringBuilder(str1);//abc串 基于String对象
        String str2 = builder1.toString();//将builder1转换为String
    }
}
